﻿using System;

class FindSequenceWithGivenSum

            // Write a program that finds in given array of integers a sequence of given sum S (if present). Example:{4, 3, 1, 4, 2, 5, 8}, S=11  {4, 2, 5}	

{
    static void Main()
    {
        Console.Write("Enter the lenght of the array: ");
        int arraySize = int.Parse(Console.ReadLine());
        Console.Write("Enter the desired sum 'S': ");
        int sum = int.Parse(Console.ReadLine());
        int[] array = new int[arraySize];
        Console.WriteLine();

        Console.WriteLine("Enter the elements of the array:");
        for (int i = 0; i < arraySize; i++)
        {
            array[i] = int.Parse(Console.ReadLine());
        }
        
        int current = 0;
        int temp = 0;
        int count = 1;
        string values = "";
        int sumCheck = array[current];
        for (int add = current + 1; add < array.Length; add++)
        {
            if (sumCheck < sum)
            {
                count += 1;
                sumCheck += array[add];
            }
            if (sumCheck == sum)
            {
                temp = sumCheck;
                for (int i = 1; i < count + 1; i++)
                {
                    values += array[current] + " ";
                    current++;
                }
                break;
            }
            if (sumCheck > sum)
            {
                count = 1;
                current += 1;
                sumCheck = array[current];
                add = current;
            }
        }
        Console.WriteLine();

        if (temp == 0)
        {
            Console.WriteLine("None of the subsets are equal to {0}", sum);
        }

        else
        { 
            Console.WriteLine("The subset that has sum equal to {0} is: {1}", sum, values);
        }
    }
}
